﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Web.Controllers
{
    public class NeedOpenReg : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            if (Certify.god || Certify.regsid != null) return;
            var s = Core.system.getSystemSettings();
            if (!s.openOutsideReg)
                context.Result = new JsonString(new
                {
                    success = false,
                    msg = "拒绝访问，不开放"
                });
        }
    }

    public class NeedOpenSendMsg : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            if (Certify.god) return;
            var s = Core.system.getSystemSettings();
            if (!s.openOutsideSendMsg && string.IsNullOrEmpty(Certify.user.sid))
                context.Result = new JsonString(new
                {
                    success = false,
                    msg = "拒绝访问，不开放"
                });
        }
    }

    public class NeedOpenDiscuss : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            if (Certify.god) return;
            var s = Core.system.getSystemSettings();
            if (!s.openDiscuss)
                context.Result = new JsonString(new
                {
                    success = false,
                    msg = "拒绝访问，不开放"
                });
        }
    }

    public class NeedOpenSendDiscuss : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            if (Certify.god) return;
            var s = Core.system.getSystemSettings();
            if (!s.openDiscuss ||
                !s.openOutsideDiscuss && string.IsNullOrEmpty(Certify.user.sid))
                context.Result = new JsonString(new
                {
                    success = false,
                    msg = "拒绝访问，不开放"
                });
        }
    }
}
